package com.sogo;

import java.util.ArrayList;   
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView.OnItemClickListener;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.database.Cursor;

public class CreateEvent extends Activity{
	
	private ListView listView;
	public String eventName;
	public String eventTime;
	public String eventLocation;
	public String eventDescription;
	public EditText ETeventName;
	public EditText ETeventTime;
	public EditText ETeventLocation;
	public EditText ETeventDescription;
	private Button btnCreateEvent;
	private int userID;
	
	JSONArray jsonArray;
	JSONObject json = new JSONObject();
	DBAdapter db = new DBAdapter(this);
	@Override
    public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.createevent);
		
		
		
		btnCreateEvent = (Button)findViewById(R.id.createeventbutton);
		
		/*calls SearchFriendClass that will then return results
		 * I don't think this is needed but will leave for now.
		 * */
		btnCreateEvent.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				ETeventName = (EditText)findViewById(R.id.eventName);
				ETeventTime = (EditText)findViewById(R.id.eventTime);
				ETeventLocation = (EditText)findViewById(R.id.eventLocation);
				ETeventDescription = (EditText)findViewById(R.id.eventDescription);
				eventName = ETeventName.getText().toString();
				eventTime = ETeventTime.getText().toString();
				eventLocation = ETeventLocation.getText().toString();
				eventDescription = ETeventDescription.getText().toString();

				try{
					db.open();
				      Cursor c = db.getUser();
				      if (c.moveToFirst())
				      {
				    	  do{
			    		        userID=c.getInt(0);
			               }while (c.moveToNext());
				      }
				      db.close();
				    
					json.put("EventName", eventName);
					json.put("EventTime", eventTime);
					json.put("EventLocation", eventLocation);
					json.put("EventDescription", eventDescription);
					json.put("UserID", userID);
					jsonArray=ServerConnection.CommunicateWithServer(json,9); //searching server
				}catch(Throwable t){};
				}
		});
		
	}
}
